POV-Ray : Newsgroups : povray.general : Tutorial for macros and arrays? : Re: Tutorial for macros and arrays? Server Time
13 Aug 2024 01:22:42 EDT (-0400)
  Re: Tutorial for macros and arrays?  
From: Spider
Date: 9 Dec 1998 19:26:15
Message: <366F1480.B3EA743F@bahnhof.se>
Yes.
It is a easy way to access a seris of numbers/vectors or object, without coding it.
The way you make a vector, you can easily modify your code to accept more numbers.
You can always do :
#declare X1 = 1;
#declare X2 = 4;
#declare X3 = 5;
#declare X4 = 2;

But it is far more cumbersome to loop through that set of numbers(almost impossible)
than
if you do it :
#declare X = array[4] { 1,4,5,2 }

To add the first, you'd have to do :
#declare NX = X1+X2+X3+X4;

The second : 
#declare C=0;
#while (C< (dimension_size(X,1)))
  #declare NX=NX+X[C];
  #declare C=C-1;
#end

This might seem to be more code, but if you have, say 2000 sample points, you realise
why
the array is far better, even more so, if you want to COMPUTE the points before, from
say
a function f(i)=i^(i-1)+1/i 

There is one of the uses for an array. Another is that a macro doesn't need to know
the
exact number of parameters, it can find it out by itself. Why is tat so good then ???
Because that you can make it much more flexible.

I hope this enlightens a bit more...

I'm not a teacher, I'm programmer, I know I can go to fast ... :-)

//Spider


David Etter Perere wrote:
> 
> Thank you Spider for your answer, but I'm located some prehistorics steps
> before.
> 
> It's the purpose of arrays and macros that I don't understand. I suppose
> that macros are something that permit to make a repetitive action, maybe a
> bit like "#while x<y ... x=x+1 ..". But arrays? A line of numbers?
> 
> That is a very very basic question. That's why I became an addict of Sonya
> Roberts's Rendering Times POVabilities. It helps me to read and change
> thinks in Colefax .INC or in DGPAS.
> 
> About Sonya Roberts, does anybody knows what's going on?
> 

> <366D138A.4820E9A0@bahnhof.se>...
> > Hello.
> > The best way of learning macros are to use them.
> >


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.